import 'package:demo/app/modules/home/home_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class TakePictureView extends GetView<HomeController> {
  final GestureTapCallback? onTap;
  final btncontroller = Get.put(_TakePictureController());
  TakePictureView({this.onTap, super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
        child: GestureDetector(
      onTapDown: (_) {
        btncontroller.setPress(true);
      },
      onTapUp: (_) {
        btncontroller.setPress(false);
        onTap?.call();
      },
      onTapCancel: () {
        btncontroller.setPress(false);
      },
      child: GetBuilder<_TakePictureController>(
        id: 'button',
        assignId: true,
        builder: (logic) {
          if (btncontroller.isPressed) {
            return Container(
              width: 70,
              height: 70,
              decoration: const BoxDecoration(
                  color: Color(0xffC3C2C2), shape: BoxShape.circle),
              child: Center(
                child: Container(
                  width: 30,
                  decoration: const BoxDecoration(
                      color: Colors.white, shape: BoxShape.circle),
                ),
              ),
            );
          } else {
            return Container(
              padding: const EdgeInsets.all(8),
              width: 70,
              height: 70,
              decoration: const BoxDecoration(
                  color: Color(0xffC3C2C2), shape: BoxShape.circle),
              child: Container(
                width: 20,
                decoration: const BoxDecoration(
                    color: Colors.white, shape: BoxShape.circle),
              ),
            );
          }
        },
      ),
    ));
  }
}

class _TakePictureController extends GetxController {
  bool isPressed = false;

  void setPress(bool b) {
    print(isPressed);
    print(b);
    isPressed = b;
    update(['button']);
  }
}
